using System.Collections.Generic;
using Guesshoo.TrainExpress.Extensions;

namespace Guesshoo.TrainExpress
{
	public class RoundTripRoute : IRoute
	{
		private readonly Route _route;
		private readonly StationLink _finalLink;
		private readonly int _lastLegTravelTime;
		private readonly IEnumerable<StationLink> _stationLinks;

		public RoundTripRoute(Route route, StationLink finalLink, int lastLegTravelTime) {
			route.ThrowIfNull("route");
			finalLink.ThrowIfNull("finalLink");

			_route = route;
			_finalLink = finalLink;
			_lastLegTravelTime = lastLegTravelTime;

			var links = new List<StationLink>();
			links.AddRange(_route.StationLinks);
			links.Add(_finalLink);

			_stationLinks = links;
		}

		public int TravelTime {
			get { return _route.TravelTime + _lastLegTravelTime; }
		}

		public IEnumerable<StationLink> StationLinks {
			get { return _stationLinks; }
		}

		public override string ToString() {
			return "{0} [{1}]".FormatWith(_route.OutputRoute(StationLinks), TravelTime);
		}
	}
}